/*
 * Copyright 2013 JROSE
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jrose.service.loader.support;

import lombok.NoArgsConstructor;
import org.jrose.core.runtime.CurrentRuntimeLevel;
import org.jrose.core.runtime.RuntimeLevel;
import org.jrose.core.util.RandomUtils;
import org.jrose.entity.constant.Gender;
import org.jrose.entity.constant.Race;
import org.jrose.entity.data.Role;
import org.jrose.entity.data.Team;
import org.jrose.entity.data.User;
import org.jrose.service.loader.support.creator.AttributeCreator;
import org.jrose.service.loader.support.creator.RoleCreator;
import org.jrose.service.loader.support.creator.TeamCreator;
import org.jrose.service.loader.support.creator.UserCreator;

import java.util.Arrays;

@NoArgsConstructor
abstract public class UnitTestSupport extends LoaderProvider {
    static {
        if (CurrentRuntimeLevel.lt(RuntimeLevel.UNIT_TEST)) {
            throw new IllegalStateException();
        }
    }

    public static Gender randomGender() {
        return RandomUtils.randomListElement(Arrays.asList(Gender.values()));
    }

    public static Race randomRace() {
        return RandomUtils.randomListElement(Arrays.asList(Race.values()));
    }

    protected UserCreator prepareUser() {
        return new UserCreator(this);
    }

    protected UserCreator prepareUser(String username) {
        return new UserCreator(this).username(username);
    }

    protected TeamCreator prepareTeam(User user) {
        return new TeamCreator(this, user);
    }

    protected RoleCreator prepareRole(Team team) {
        return new RoleCreator(this, team);
    }

    protected AttributeCreator prepareAttribute(Role role) {
        return new AttributeCreator(this, role);
    }
}
